package com.huawei.appmarket.service.store.awk.card;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appmarket.framework.widget.RoundCornerLayout;
import com.huawei.appmarket.framework.widget.RoundImageView;
import com.huawei.appmarket.service.store.awk.bean.SubstanceImgCardBean;
import o.azb;
import o.cgz;
import o.Logger;
import o.dof;
import o.epv;
import o.eqx;
import o.ewm.d;
import o.ewm.e;
import o.ewm.j;

public class SubstanceImgCard extends BaseDistCard {
    private SubstanceImgCardBean ʻ;
    private boolean ʼ;
    private ImageView ʽ;
    private int ˊॱ;
    private RoundImageView ˋ;
    private int ॱˊ;
    private TextView ॱॱ;
    private RoundCornerLayout ᐝ;

    public SubstanceImgCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        this.ˋ = (RoundImageView) view.findViewById(j.ʾˑ);
        this.ᐝ = (RoundCornerLayout) view.findViewById(j.ﹺ);
        azb.ˋ(this.ᐝ);
        this.ʽ = (ImageView) view.findViewById(j.ʾˌ);
        this.ॱॱ = (TextView) view.findViewById(j.ʽﾟ);
        ʽ(view);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof SubstanceImgCardBean) {
            this.ʻ = (SubstanceImgCardBean) cardBean;
            this.ʼ = cardBean.ॱˍ();
            String ˊ = this.ʻ.ˊ();
            if (TextUtils.isEmpty(this.ʻ.ꓸ())) {
                this.ᐝ.setVisibility(8);
                this.ˋ.setVisibility(0);
                this.ˋ.setImageResource(e.ꜞ);
                if (!this.ʼ) {
                    int ʽ = this.ʻ.ʽ();
                    int ˊ2 = azb.ˊ(this.ʼॱ);
                    int ˏ = azb.ˏ(this.ʼॱ);
                    int ʻ = epv.ʻ(this.ʼॱ);
                    LayoutParams layoutParams = (LayoutParams) this.ˋ.getLayoutParams();
                    if (ʽ == 0) {
                        layoutParams.setMargins(ˊ2, 0, ˏ, 0);
                        this.ˋ.setRadius(ʻ);
                    } else {
                        layoutParams.setMargins(0, 0, 0, 0);
                        this.ˋ.setRadius(0);
                    }
                }
                if (!dof.ॱ(ˊ)) {
                    ˎ(this.ʻ.ꜟ());
                    if (this.ʻ.ॱ() == 0) {
                        ˏ(ˊ);
                        return;
                    } else {
                        eqx.ˏ(this.ˋ, ˊ);
                        return;
                    }
                }
                return;
            }
            this.ˋ.setVisibility(8);
            this.ᐝ.setVisibility(0);
            ˋ();
            if (!dof.ॱ(ˊ)) {
                if (this.ʻ.ॱ() == 0) {
                    eqx.ˏ(this.ʽ, ˊ, "image_default_icon");
                } else {
                    eqx.ˏ(this.ʽ, ˊ);
                }
            }
            this.ॱॱ.setText(this.ʻ.ꓸ());
        }
    }

    private void ˏ(String str) {
        if (this.ˊॱ >= 4096) {
            eqx.ˋ((int) Math.floor(((double) (this.ॱˊ * 4096)) / ((double) this.ˊॱ)), 4096, this.ˋ, str, "image_default_icon");
        } else {
            eqx.ˏ(this.ˋ, str, "image_default_icon");
        }
    }

    private double ˊ(String str) {
        if (TextUtils.isEmpty(str) || !str.contains("x")) {
            return 0.5625d;
        }
        int indexOf = str.indexOf("x");
        if (indexOf <= 0 || str.length() <= indexOf + 1) {
            return 0.5625d;
        }
        try {
            this.ॱˊ = Integer.parseInt(str.substring(0, indexOf).trim());
            this.ˊॱ = Integer.parseInt(str.substring(indexOf + 1, str.length()).trim());
            if (this.ॱˊ > 0) {
                return ((double) this.ˊॱ) / ((double) this.ॱˊ);
            }
            return 0.5625d;
        } catch (NumberFormatException e) {
            Logger.e("substanceImgCard", e.toString());
            return 0.5625d;
        }
    }

    private void ˎ(String str) {
        int i;
        if (this.ʼ) {
            i = 1;
        } else {
            i = this.ʻ.ʽ();
        }
        double ˊ = ˊ(str);
        int ˊ2 = azb.ˊ(this.ʼॱ);
        int ˏ = azb.ˏ(this.ʼॱ);
        int ʻ = epv.ʻ(this.ʼॱ);
        int ˎ = epv.ˎ(this.ʼॱ);
        LayoutParams layoutParams = (LayoutParams) this.ˋ.getLayoutParams();
        if (i == 0) {
            i = (ˎ - ˊ2) - ˏ;
            layoutParams.setMargins(ˊ2, 0, ˏ, 0);
            this.ˋ.setRadius(ʻ);
        } else {
            layoutParams.setMargins(0, 0, 0, 0);
            this.ˋ.setRadius(0);
            i = ˎ;
        }
        ˎ = (int) (((double) i) * ˊ);
        layoutParams.width = i;
        layoutParams.height = ˎ;
        this.ˋ.setLayoutParams(layoutParams);
    }

    private void ˋ() {
        LayoutParams layoutParams = (LayoutParams) this.ᐝ.getLayoutParams();
        RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) this.ʽ.getLayoutParams();
        int ˊ = azb.ˊ(this.ʼॱ);
        int ˏ = azb.ˏ(this.ʼॱ);
        int dimensionPixelSize = this.ʼॱ.getResources().getDimensionPixelSize(d.ˊॱ);
        ˊ = (epv.ˎ(this.ʼॱ) - ˊ) - ˏ;
        ˏ = (ˊ * 9) / 21;
        layoutParams.width = ˊ;
        if (this.ʼ) {
            layoutParams.topMargin = dimensionPixelSize;
        }
        this.ᐝ.setLayoutParams(layoutParams);
        layoutParams2.width = ˊ;
        layoutParams2.height = ˏ;
        this.ʽ.setLayoutParams(layoutParams2);
    }
}
